import { MockMethod } from 'vite-plugin-mock';
import { resultError, resultPageSuccess, resultSuccess } from '../_util';

const deviceList = (() => {
  const result: any[] = [];
  for (let index = 0; index < 20; index++) {
    result.push({
      id: `${index}`,
      name: '@cname()',
      'code|1-3': 'code',
      type: '@cname()',
      'building|1-10': 1,
      'floor|1-4': 1,
      // remark: '@cword(10,20)',
      'dept|0-4': 1,
      'status|1': ['0', '1'],
    });
  }
  return result;
})();

const dataList = (() => {
  const result: any[] = [];
  for (let index = 0; index < 20; index++) {
    result.push({
      id: `${index}`,
      name: '@cword(1,4)',
      createtime: '@datetime',
      updatetime: '@datetime',
      'code|1-3': 'code',
      updator: '@cname()',
      'value|1-10': 1,
    });
  }
  return result;
})();

const classifyList = (() => {
  const result: any[] = [];
  for (let index = 0; index < 20; index++) {
    result.push({
      id: `${index}`,
      name: '@cname()',
      code: '@cword(1,4)',
      type: '自动',
      params: '@cword(1,4)',
      'coefficient|1-5': 1,
      'building|1-10': 1,
      'floor|1-4': 1,
      'dept|0-2': 1,
    });
  }
  return result;
})();

const dataTypeList = (() => {
  const result: any[] = [];
  for (let index = 0; index < 3; index++) {
    result.push({
      id: `${index}`,
      deptName: ['电力系统', '空调系统', '水系统'][index],
      orderNo: index + 1,
      createTime: '@datetime',
      remark: '@cword(10,20)',
      'status|1': ['0', '0', '1'],
      children: (() => {
        const children: any[] = [];
        for (let j = 0; j < 3; j++) {
          children.push({
            id: `${index}-${j}`,
            deptName: ['照明系统', 'UT', 'Process'][j],
            orderNo: j + 1,
            createTime: '@datetime',
            remark: '@cword(10,20)',
            'status|1': ['0', '1'],
            parentDept: `${index}`,
            children: undefined,
          });
        }
        return children;
      })(),
    });
  }
  return result;
})();

const recordTypeList = (() => {
  const result: any[] = [];
  for (let index = 0; index < 4; index++) {
    result.push({
      id: `${index}`,
      deptName: ['电表', '水表', '燃气表', '传感器'][index],
      orderNo: index + 1,
      createTime: '@datetime',
      remark: '@cword(10,20)',
      'status|1': ['0', '0', '1'],
      children: (() => {
        const children: any[] = [];
        for (let j = 0; j < 3; j++) {
          children.push({
            id: `${index}-${j}`,
            deptName: ['电表1', '电表2', '电表3'][j],
            orderNo: j + 1,
            createTime: '@datetime',
            remark: '@cword(10,20)',
            'status|1': ['0', '1'],
            parentDept: `${index}`,
            children: undefined,
          });
        }
        return children;
      })(),
    });
  }
  return result;
})();
const deviceTypeList = (() => {
  const result: any[] = [];
  for (let index = 0; index < 5; index++) {
    result.push({
      id: `${index}`,
      deptName: ['电表', '水表', '燃气表', '环境传感器', '消防设备'][index],
      orderNo: index + 1,
      createTime: '@datetime',
      remark: '@cword(10,20)',
      'status|1': ['0', '0', '1'],
      // children: (() => {
      //   const children: any[] = [];
      //   for (let j = 0; j < 4; j++) {
      //     children.push({
      //       id: `${index}-${j}`,
      //       deptName: ['研发部', '市场部', '商务部', '财务部'][j],
      //       orderNo: j + 1,
      //       createTime: '@datetime',
      //       remark: '@cword(10,20)',
      //       'status|1': ['0', '1'],
      //       parentDept: `${index}`,
      //       children: undefined,
      //     });
      //   }
      //   return children;
      // })(),
    });
  }
  return result;
})();

export default [
  {
    url: '/basic-api/collection/getDeviceList',
    timeout: 100,
    method: 'get',
    response: ({ query }) => {
      const { page = 1, pageSize = 20 } = query;
      return resultPageSuccess(page, pageSize, deviceList);
    },
  },
  {
    url: '/basic-api/collection/getDataList',
    timeout: 100,
    method: 'get',
    response: ({ query }) => {
      const { page = 1, pageSize = 20 } = query;
      return resultPageSuccess(page, pageSize, dataList);
    },
  },
  {
    url: '/basic-api/collection/getClassifyList',
    timeout: 100,
    method: 'get',
    response: ({ query }) => {
      const { page = 1, pageSize = 20 } = query;
      return resultPageSuccess(page, pageSize, classifyList);
    },
  },
  {
    url: '/basic-api/collection/getDataTypeList',
    timeout: 100,
    method: 'get',
    response: () => {
      return resultSuccess(dataTypeList);
    },
  },
  {
    url: '/basic-api/collection/getDeviceTypeList',
    timeout: 100,
    method: 'get',
    response: () => {
      return resultSuccess(deviceTypeList);
    },
  },
  {
    url: '/basic-api/collection/getRecordTypeList',
    timeout: 100,
    method: 'get',
    response: () => {
      return resultSuccess(recordTypeList);
    },
  },
  {
    url: '/basic-api/system/setRoleStatus',
    timeout: 500,
    method: 'post',
    response: ({ query }) => {
      const { id, status } = query;
      return resultSuccess({ id, status });
    },
  },
] as MockMethod[];
